var express = require('express');
var router = express.Router();

// 配置数据库引擎
const modle = require("../modle/db")

// 连结地址

let src=require("../config/index")

// 轮播图接口功能

router.get("/banners",async (req, res) => { 
    let sql = `select id,concat("${src}","/uploads/",image_src) as image_src ,title,isshow from e_banners where isshow=1`;
    let [ err, data ] = await modle.query(sql)
    if (err) {
        res.send({ "data": "400", "mas": "查询失败" })
    } else { 
        res.send({"data":"200","mas":"查询成功",data:data})
    }
})

// 同步课程接口
router.get("/course", async (req, res) => { 
    let { type = 1 } = req.query;
    let limit = type == 1 ? 8 : 6;
    let sql = `select id,cid,title,price,concat("${src}","/uploads/course/",image_src) as image_src,intro, concat("${src}","/uploads/course/",detail_imgs) as detail_imgs,type,type_name,area_name,grade_name,subject_name,category_name,tid,status from e_course where type=${type} order by id desc limit ${limit}`
    let [err, data] = await modle.query(sql)
    res.send(data)
})

module.exports = router;